#include "worldarea.h"

namespace infinity {

void WorldArea::removeSector(WorldSector* sector)
{
	dwAssert(sector != NULL, "Invalid parameter: sector is NULL");
	dwAssert(getAreaIdFromSector(sector->getId()) == m_id, "Invalid parameter: sector doesn't belong to this area");
	dwAssert(std::find(m_sectors.begin(), m_sectors.end(), sector) != m_sectors.end(), "Invalid parameter: sector is not registered in this area");

	SectorsCollection::iterator end = m_sectors.end();

	for (SectorsCollection::iterator sectorIt = m_sectors.begin(); sectorIt != end; ++sectorIt)
	{
		if (*sectorIt == sector)
		{
			m_sectors.erase(sectorIt);
			break ;
		}
	}
}

WorldSector* WorldArea::getSector(const Vector3i& sectorId)
{
	dwAssert(getAreaIdFromSector(sectorId) == m_id, "Invalid parameter: sector doesn't belong to this area");

	SectorsCollection::iterator end = m_sectors.end();

	for (SectorsCollection::iterator sectorIt = m_sectors.begin(); sectorIt != end; ++sectorIt)
	{
		WorldSector* sector = *sectorIt;

		dwAssert(sector != NULL, "Invalid internal state");

		if (sector->getId() == sectorId)
		{
			return sector;
		}
	}

	return NULL;
}

} // namespace infinity
